import 'package:flutter/material.dart';

class ColorsUtils {
  ColorsUtils._();

  static const String colorAaaa = '#AAAAAA';

  static const String color096d = '#096DD9';

  static const String color3333 = '#333333';

  static const String colorF2f2 = '#F2F2F2';

  static const String colorFfff = '#FFFFFF';

  static const String color5555 = '#555555';

  static const String colorD7d7 = '#D7D7D7';

  static const String color0000 = '#000000';

  static const String colorCccc = '#cccccc';

  static const String color9999 = '#999999';

  static const String colorF522 = '#F5222D';

  static const String colorE6f0 = '#e6f0ff';

  static const String color7F7f = '#7F7F7F';

  static Color fromRGBO(
      [int r = 255, int g = 255, int b = 255, double opacity = 1.0]) {
    return Color.fromRGBO(r, g, b, opacity);
  }

  static Color rgba(
      [int r = 255, int g = 255, int b = 255, double opacity = 1.0]) {
    return fromRGBO(r, g, b, opacity);
  }

  static Color parseColorFromHexString(String code) {
    Color result = Colors.red;
    int value = 0;
    if (code.contains('#')) {
      try {
        value = int.parse(code.substring(1), radix: 16);
      } catch (e) {
        debugPrint(e.toString());
      }
      switch (code.length) {
        case const (1 + 6):

          ///6位
          result = Color(value + 0xFF000000);
          break;
        case const (1 + 8):

          ///8位
          result = Color(value);
          break;
        default:
          result = Colors.red;
      }
    } else {
      try {
        value = int.parse(code, radix: 16);
      } catch (e) {
        debugPrint('$e');
      }
      switch (code.length) {
        case 6:
          result = Color(value + 0xFF000000);
          break;
        case 8:
          result = Color(value);
          break;
        default:
          result = Colors.red;
      }
    }
    return result;
  }

  static Color colorFromHexString(String? s) {
    return parseColorFromHexString(s ?? colorFfff);
  }
}
